# -*- coding: utf-8 -*-
from tool import *
import sys

print sys.getdefaultencoding()


print float2str(12345676732452.22)
print str2float('5,017,869,518.74')

print str_add('1,758,096,475.13', '88,226,475.83')
print str_div(str_mul('1,846,322,950.96', '100'), '5,017,869,518.74')

print '测试'


def parse_code_name(lines):
    for line in lines:
        if line.startswith('公司代码'):
            for x in line.split(' '):
                if x.startswith('公司代码'):
                    code = x.split('：')[1]
                if x.startswith('公司简称'):
                    name = x.split('：')[1]
                    return code, name
    return None, None


def parse_total(lines):
    total_flag = False
    for line in lines:
        if line.startswith('主要会计数据 '):

        if total_flag:
            if ',' in line and '.' in line:
                total = line.split(' ')[0].strip(' ')
                return total


def parse_ss1(lines):

    pass


def parse_txt_file(file_name):
    with open(file_name, 'r') as f:
        lines = f.readlines()

        code, name = parse_code_name(lines)
        if code:
            print code, name.decode('utf-8')
        print parse_total(lines)


parse_txt_file('600017_2018_z.txt')
parse_txt_file('600176_2018_z.txt')
parse_txt_file('600526_2018_z.txt')
